package myBatis.role;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * Hello world!
 *
 */
public class App {
	private static void userHashMap(SqlSession session) {
		String statement = "mapping.user.getUsersById";
		User user = session.selectOne(statement, 1);
		System.out.println(user);
	}
	
	private static void addNewUser(SqlSession session,User user){
		String statement = "mapping.user.insert";
		int count = session.insert(statement,user);
		session.commit();
		System.out.println("insert count:"+count);
	}
	
	private static void myObjectExample(){}
	public static void main(String[] args) {
		String resource = "mybatis2.conf.xml";
		InputStream is = App.class.getClassLoader().getResourceAsStream(resource);
		SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
		SqlSession session = sessionFactory.openSession();

		String statement = "mapping.user.getAllUsers";
		List<User> users = session.selectList(statement);
		for (User u : users) {
			System.out.println(u);
		}

//		statement = "mapping.getUserAttrMapById";
//		Map<String, Object> map = session.selectOne(statement, 1);
//		for (String key : map.keySet()) {
//			System.out.println("key" + key + "value:" + map.get(key) + "vt" + map.get(key).getClass());
//		}
		System.out.println("Hello World!");
	}
}
